﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Walson.Form.Common
{
    public partial class Switch : UserControl
    {
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler Click;
        protected override void OnClick(EventArgs e)
        {
            if (this.Click != null)
            {
                Click(this, e);
            }
        }

        public new event EventHandler StateChanged;
        protected void RaiseStateChanged()
        {
            if (this.StateChanged != null)
            {
                StateChanged(this, null);
            }
        }

        private bool _On = true;
        public bool On
        {
            get
            {
                return _On;
            }
            set
            {
                if (_On != value)
                {
                    _On = value;
                    RaiseStateChanged();
                    if (this.On)
                        pictureBox1.BackgroundImage = Walson.Properties.Resources.Switch1;
                    else
                        pictureBox1.BackgroundImage = Walson.Properties.Resources.Switch2;
                }
            }
        }

        public Switch()
        {
            InitializeComponent();
            pictureBox1.BackgroundImage = Walson.Properties.Resources.Switch1;

            pictureBox1.Click += delegate
            {
                this.On = !this.On;
            };
        }
    }
}
